package operate;

import book.BookList;

import java.util.Scanner;

public class BorrowOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书！");
        System.out.print("输入要借阅书名：");
        Scanner in = new Scanner(System.in);
        String name = in.nextLine();

        for (int i = 0; i < bookList.getUsedSize(); i++) {
            //有这本书，且为被借出
            if (name.equals(bookList.getBook(i).getName()) &&
                    !bookList.getBook(i).isBorrowed()) {
                bookList.getBook(i).setBorrowed(true);
                System.out.println("借阅成功！");
                return;
            }
        }

        System.out.println("借阅失败，"+name+"已被借出或不存在！");
    }
}
